package com.golang.api.function;

import cn.hutool.core.collection.CollectionUtil;
import com.golang.api.domain.Tag;
import com.golang.api.dto.request.TagInfoDto;
import com.golang.api.dto.response.TagInfoRespDto;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public interface TagFunction {


    default Function<List<Tag>, List<TagInfoRespDto>> listInfos2Items(List<Tag> entities) {
        return dtos -> CollectionUtil.emptyIfNull(entities).stream().map(o -> new TagInfoRespDto()
                .setTagId(o.getId())
                .setTagName(o.getTagName())

        ).collect(Collectors.toList());
    }


    default Function<TagInfoDto, Tag> TagInfoDto2Tag(TagInfoDto dto) {
        return a -> {
            Tag tag = new Tag()
                    .setTagName(dto.getTagName())
                    .setTagType(dto.getTagType());
            return tag;
        };

    }

}
